<template>
  <!-- 安全演练记录 -->
  <view class="fireSkits">
    <view class="wrapper-content">
      <scroll-view
        scroll-y="true"
        @scrolltolower="scrollBottom"
        @scroll="scrollHeight"
        :style="[
          {
            height: !loading && !noMore ? '100%' : '100%',
          },
        ]"
        v-if="dataSource.length"
      >
        <view
          class="allList wrapper-item"
          v-for="(item, i) in dataSource"
          :key="i"
          :data-url="`/fireFighting/fireSkits/fireSkitsDetail?id=${item.id}`"
          @click="handleClickRouter"
        >
          <view class="rtEmployee">
            <view class="line2-hidden title">
              {{ item.drillTheme || "" }}
            </view>
            <view class="line-hidden footer">
              演练地点：<text>{{ item.drillPlace }}</text>
            </view>
            <view class="line-hidden footer">
              演练时间：<text>{{
                formatters(item.drillTime, "YY/MM/DD HH:mm")
              }}</text>
            </view>
            <view class="line-hidden footer">
              演练人员：<text>{{ item.drillPerson || "" }}</text>
            </view>
          </view>
        </view>
        <view class="pageBottom" v-if="pageBottom">—— 到底了 ——</view>
      </scroll-view>

      <view v-if="!dataSource.length">
        <u-empty
          mode="list"
          text="暂无内容！"
          :icon="baseImgUrl + 'no-icon2.png'"
        >
        </u-empty>
      </view>
    </view>

    <view class="btns">
      <button
        class="submit-btn"
        type="primary"
        style="width: 100%"
        :data-url="`/fireFighting/newFireTraining/newFireTraining?companyId=${options.companyId}`"
        @click="handleClickRouter"
      >
        添加安全演练
      </button>
    </view>
  </view>
</template>

<script>
import { FireDrillPage } from "@/api/myself.js";
import { handleClickRouter, formatters } from "@/utils/util.js";

export default {
  data() {
    return {
      baseImgUrl: this.$baseImgUrl,
      imgPrefix: uni.getStorageSync("imgPrefix"),
      options: {},
      scrollTop: 0,
      dataSource: [],
      pageBottom: false,
      pageConfig: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  onLoad(options) {
    this.options = options;
    this.scrollTop = 0;
    uni.removeStorageSync("scrollTop");

    this.pageConfig.pageNo = 1;
    this.dataSource = [];
    this.getList();
  },
  onShow() {
    this.scrollTop = uni.getStorageSync("scrollTop") || 0;

    let fireSkits = uni.getStorageSync("fireSkits");
    if (fireSkits) {
      this.pageConfig.pageNo = 1;
      this.dataSource = [];
      this.getList();
      uni.setStorageSync("fireSkits", false);
    }
  },
  methods: {
    handleClickRouter,
    formatters,
    scrollHeight(e) {
      uni.setStorageSync("scrollTop", e.detail.scrollTop);
    },
    scrollBottom(e) {
      let current = (this.pageConfig.pageNo += 1);
      let pages = Math.ceil(this.pageConfig.total / this.pageConfig.pageSize);
      if (current <= pages) {
        this.getList();
      } else {
        this.pageBottom = true;
      }
    },
    getList() {
      let data = {
        companyId: this.options.companyId,
        pageNo: this.pageConfig.pageNo,
        pageSize: this.pageConfig.pageSize,
      };

      FireDrillPage(data).then((res) => {
        this.dataSource = this.dataSource.concat(res.result.records || []);
        this.pageConfig.total = res.result.total;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.fireSkits {
  height: 100%;

  .wrapper-content {
    padding: 24rpx 16rpx;
    height: calc(100vh - 72px);
    background: #f8f9fb;

    .wrapper-item {
      padding: 30rpx 35rpx;
      background-color: #ffffff;
      margin-bottom: 20rpx;

      .rtEmployee {
        line-height: 53rpx;
        width: 100%;

        .title {
          font-weight: bold;
          font-size: 32rpx;
          color: #333333;
        }

        .footer {
          color: #a1a1a1;

          text {
            color: #666666;
          }
        }
      }
    }
  }
}
</style>
